﻿@{
    ViewBag.Title = "领料输入";
    Layout = "~/Views/Shared/_ManufactureList.cshtml";
}
<script>
    var FProCompanyNO = "";
    $(function () {
        initControl();
        gridList();
        textChange();
    });

    function initControl() {
        $('select').bindSelect();
        //领料单位
        $("#FHappenCompanyNO").bindSelect({
            url: "/BaseData/ZSJ_B1_GH_SI/GetPickCompany?isCustomer=1",
            id: "UnitNO",
            text: "UnitNOShortName",
            search: true
        });
        //供货单位
        $("#txtqueryFProCompanyNO").bindSelect({
            url: "/BaseData/ZSJ_B1_GH_SI/GetProCompany?isProduct=1",
            id: "UnitNO",
            text: "UnitNOShortName",
            search: true
        });
        //容器编号
        $("#txtFContainerNO").bindSelect({
            url: "/BaseData/ZSJ_21_RQ_DatContainer/GetGridJson",
            id: "FContainerNO",
            text: "FContainerNO"
        });
        //托盘编号
        $("#txtFPalletNO").bindSelect({
            url: "/BaseData/ZSJ_22_TP_Pallet/GetGridJson",
            id: "PalletNO",
            text: "PalletNO"
        });

        //初始化入库日期、凭证编号、批次号
        SetSomeData();
    }

    function SetSomeData()
    {
        var currentDate = new Date();
        $("#txtFCurDate").val(currentDate.format("yyyy-MM-dd"));
        $("#txtFVoucherNo").val(currentDate.format("yyyyMMddhh"));
        $("#txtFBatchNo").val(currentDate.format("yyyyMMdd"));
    }

    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/VBaseData/V_ZSJ_12_GH_SuProduction_DatStor/GetListForPick",
            height: $(window).height() - 270,
            colModel: [
            { label: '选择', name: 'XZ', width: 80, align: 'center' },
            { label: "id", name: "FRegisterID", width: 120, align: 'center', hidden: true },
            { label: "领料单位", name: "FHappenCompanyNO", width: 120, align: 'center' },
            { label: "领料单位名称", name: "FHappenCompanyName", width: 120, align: 'center' },
            { label: '领料日期', name: 'FCurDate', width: 100, align: 'center' },
            { label: '零件编号', name: 'FProductionNO', width:140, align: 'center' },
            { label: '零件名称', name: 'FProductionName', width: 100, align: 'center' },
            { label: '批次号', name: 'FBatchNo', width: 80, align: 'center' },
            { label: '开票数量', name: 'FQuantity_KP', width: 80, align: 'center' },
            { label: '实际数量', name: 'FQuantity', width: 80, align: 'center' },
            { label: '容器编号', name: 'FContainerNO', width: 80, align: 'center' },
            { label: '容器名称', name: 'FBookQuantity', width: 80, align: 'center' },
            { label: '容器数量', name: 'FContainerQuantity', width: 80, align: 'center' },
            { label: '实际装箱', name: 'FFactContent', width: 80, align: 'center' },
            { label: '标准装箱', name: 'FContent', width: 80, align: 'center' },
            { label: '托盘编号', name: 'FPalletNO', width: 80, align: 'center' },
            { label: '托盘数量', name: 'FPalletQuantity', width: 80, align: 'center' },
            { label: '实际托盘容量', name: 'FPalletFactContent', width: 80, align: 'center' },
            { label: '标准托盘容量', name: 'FPalletContent', width: 80, align: 'center' },
            { label: '凭证编号', name: 'FVoucherNo', width: 80, align: 'center' },
            { label: '备注', name: 'FDescription', width: 80, align: 'center' },
            { label: '供货单位', name: 'FProCompanyNO', width: 80, align: 'center' },
            { label: '供货单位名称', name: 'FProCompanyName', width: 80, align: 'center' },
            { label: '零件状态', name: 'FProductionTypeNO', width: 80, align: 'center' },
            { label: '输入人员', name: 'FCreateBy', width: 80, align: 'center' },
            { label: '输入日期', name: 'FCreateDate', width: 80, align: 'center' },
            { label: '输入时间', name: 'FCreateTime', width: 80, align: 'center' },
            ],
            viewrecords: true,
            onSelectRow: function (rowId) {
                rowData = $gridList.jqGrid('getRowData', rowId);
                $("#form1").formSerialize(rowData, "txt");
                FProCompanyNO = rowData["FProCompanyNO"];
                SetSomeData();
            }
        });

        $("#btn_search").click(function () {
            query($gridList);
        });

    }

    function query(obj) {
        obj.jqGrid('setGridParam', {
            postData: {currentDate:$("#txtFCurDate").val(),companyNo: $("#txtqueryFProCompanyNO").val(), productionNO: $("#txtqueryFProductionNO").val(), productionName: $("#txtqueryFProductionName").val() }
        }).trigger('reloadGrid');
    }

    function textChange()
    {
        $("#form1").find(".decimal").keyup(function () {
            var $FactContent = 1;
            var $FQuantity_KP = $("#txtFQuantity_KP").val();
            var $FFactContent = $("#txtFFactContent").val();
            var $FPalletFactContent = $("#txtFPalletFactContent").val();
            if ($FFactContent != "")
            {
                $FactContent = Math.ceil($FQuantity_KP / $FFactContent);
                $("#txtFContainerQuantity").val($FactContent);
            }
            if($FPalletFactContent!="")
            {
                $("#txtFPalletQuantity").val(Math.ceil($FactContent / $FPalletFactContent));
            }
        });
    }

    function btn_Return() {
        parent.$.reload();
        parent.$.detailClose();
    }

    function btn_Ok() {
        if (!$('#form1').formValid()) {
            return false;
        }
        var postData = $("#form1").formSerialize();
        postData["FHappenCompanyNO"] = $("#FHappenCompanyNO").val();
        postData["FProCompanyNO"] = FProCompanyNO;
        $.submitForm({
            url: "/WareHouse/EnterWareHouse/SaveDJ_StoRegisterCC",
            param: postData,
            success: function () {
                $("#gridList").trigger("reloadGrid");
            }
        });
    }

</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-center">
        <form id="form1">
            <div><input id="txtFRegisterID" name="FRegisterID" type="hidden" /><input id="txtFProductionTypeNO" name="FProductionTypeNO" type="hidden" /></div>
            <div style="padding-top: 1px;margin-left:10px;">
                <table class="form" style="width:97%;text-align:left;margin:0px;margin-top:-20px;margin-bottom:-3px; border-bottom:2px solid #ccc;">
                    <tr>
                        <td style="width:97%; padding: 5px 10px;">
                            <div class="btn-group" style="margin-left:500px;margin-bottom:-10px;">
                                <h2 style="font-family:隶书;font-weight:bold;font-size:26px"> 输入</h2>
                            </div>
                            <div class="btn-group" style="margin-left:470px;margin-bottom:-25px;">
                                <a id="" class="btn btn-primary center-block " onclick="btn_Ok()"><span class="glyphicon glyphicon-ok"></span> 新增</a>
                            </div>
                            <div class="btn-group" style="margin-left:30px;margin-bottom:-25px;">
                                <a id="" class="btn btn-primary center-block  " onclick="btn_Return()"><span class="glyphicon glyphicon-remove"></span> 返回</a>
                            </div>
                        </td>
                    </tr>
                </table>

                <table class="form" style="width:97%;text-align:left;margin:0px;margin-top:0px;margin-bottom:0px; border-bottom:1px solid #ccc;">
                    <tr>
                        <th class="formTitle" style="width:100px;">零件编号</th>
                        <td class="formValue" style="width:120px;">
                            <input id="txtqueryFProductionNO" type="text" class="form-control " value="" />
                        </td>
                        <th class="formTitle" style="width:100px;">零件名称</th>
                        <td class="formValue" style="width:120px;">
                            <input id="txtqueryFProductionName" type="text" class="form-control " value="" />
                        </td>
                        <th class="formTitle" style="width:155px;">供货单位</th>
                        <td class="formValue" style="width:160px;">
                            <select id="txtqueryFProCompanyNO" class="form-control">
                                <option value="">==请选择==</option>
                            </select>
                        </td>
                        <td style="padding: 5px 10px;">
                            <div class="btn-group" style="margin-left:70px;margin-bottom:-2px;">
                                <a id="btn_search" class="btn btn-primary center-block  " onclick="btn_search();"><span class="glyphicon glyphicon-search"></span> 查询</a>
                            </div>
                        </td>

                    </tr>
                </table>

                <table class="form" style="width:97%;text-align:left;margin:0px;margin-top:0px;margin-bottom:0px;">
                    <tr>
                        <th class="formTitle" style="width:100px;">领料单位</th>
                        <td class="formValue" style="width:120px;">
                            <select id="FHappenCompanyNO" class="form-control required">
                                <option value="">==请选择==</option>
                            </select>
                        </td>
                        <th class="formTitle" style="width:100px;">出库日期</th>
                        <td class="formValue" style="width:120px;height:20px;">
                            <input id="txtFCurDate" name="FCurDate" type="text" class="form-control required" value="" onfocus="WdatePicker()" />
                        </td>
                        <th class="formTitle" style="width:100px;">凭证编号</th>
                        <td class="formValue" style="width:120px;height:20px;">
                            <input id="txtFVoucherNo" name="FVoucherNo" type="text" class="form-control required" value="" />
                        </td>
                        <th class="formTitle" style="width:100px;">批次号</th>
                        <td class="formValue" style="width:120px;">
                            <input id="txtFBatchNo" name="FBatchNo" type="text" class="form-control required" value="" />
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle" style="width:100px;">零部件号</th>
                        <td class="formValue" style="width:120px;">
                            <input id="txtFProductionNO" name="FProductionNO" type="text" class="form-control required" value="" />
                        </td>
                        <th class="formTitle" style="width:100px;">零件名称</th>
                        <td class="formValue" style="width:120px;">
                            <input id="txtFProductionName" type="text" class="form-control required" value="" />
                        </td>
                        <th class="formTitle" style="width:100px;">备注</th>
                        <td class="formValue" style="width:120px;">
                            <input id="txtFDescription" name="FDescription" type="text" class="form-control " value="" />
                        </td>
                        <th class="formTitle" style="width:100px;">开票数量</th>
                        <td class="formValue">
                            <input id="txtFQuantity_KP" name="FQuantity_KP" type="text" class="form-control text-right required decimal" style="width:80px;margin-left:0px;" /><label class="suffix">件</label>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle" style="width:100px;">容器编号</th>
                        <td class="formValue" style="width:160px;">
                            <select id="txtFContainerNO" name="FContainerNO" class="form-control required">
                                <option value="">==请选择==</option>
                            </select>
                        </td>
                        <th class="formTitle" style="width:100px;">实际装箱</th>
                        <td class="formValue">
                            <input id="txtFFactContent" name="FFactContent" type="text" class="form-control text-right required decimal" style="width:80px;margin-left:0px;" /><label class="suffix ">件/箱</label>
                        </td>
                        <th class="formTitle" style="width:100px;">标准装箱</th>
                        <td class="formValue">
                            <input id="txtFContent" name="FContent" type="text" class="form-control text-right required " style="width:80px;margin-left:0px;" /><label class="suffix">件/箱</label>
                        </td>
                        <th class="formTitle" style="width:100px;">容器数量</th>
                        <td class="formValue">
                            <input id="txtFContainerQuantity" name="FContainerQuantity" type="text" class="form-control text-right required" style="width:80px;margin-left:0px;" /><label class="suffix">箱</label>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">托盘编号</th>
                        <td class="formValue" style="width:160px;">
                            <select id="txtFPalletNO" name="FPalletNO" class="form-control required">
                                <option value="">==请选择==</option>
                            </select>
                        </td>
                        <th class="formTitle" style="width:100px;">实际托盘容量</th>
                        <td class="formValue">
                            <input id="txtFPalletFactContent" name="FPalletFactContent" type="text" class="form-control text-right required decimal" style="width:80px;margin-left:0px;" /><label class="suffix">箱/托</label>
                        </td>
                        <th class="formTitle" style="width:100px;">标准托盘容量</th>
                        <td class="formValue">
                            <input id="txtFPalletContent" name="FPalletContent" type="text" class="form-control text-right required" style="width:80px;margin-left:0px;" /><label class="suffix">箱/托</label>
                        </td>
                        <th class="formTitle" style="width:100px;">托盘数量</th>
                        <td class="formValue">
                            <input id="txtFPalletQuantity" name="FPalletQuantity" type="text" class="form-control text-right required" style="width:80px;margin-left:0px;" /><label class="suffix">箱</label>
                        </td>
                    </tr>
                </table>
            </div>
        </form>
        <br />
        <div style="">
            <table id="gridList"></table>
        </div>
    </div>
</div>


